﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.ValentineUI {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import flash.utils.*;
    import Classes.*;
    import flash.text.*;
    import org.aswing.event.*;
    import Classes.orders.Valentines2011.*;
    import Modules.stats.types.*;
    import com.zynga.skelly.util.*;

    public class PicturePane extends Sprite {

        protected var m_data:Dictionary;
        protected var m_senders:Dictionary;
        protected var m_recipients:Dictionary;
        protected var m_objects:Dictionary;
        protected var m_backgrounds:Dictionary;
        protected var m_imageSprite:Sprite;
        protected var m_bgHolder:Sprite;
        protected var m_senderHolder:Sprite;
        protected var m_recipientHolder:Sprite;
        protected var m_objectHolder:Sprite;
        protected var m_curSender:int = 1;
        protected var m_curRecipient:int = 1;
        protected var m_curObject:int = 1;
        protected var m_curBackground:int = 1;

        public function PicturePane(_arg1:Dictionary, _arg2:ValentineCard=null){
            this.m_senders = new Dictionary(true);
            this.m_recipients = new Dictionary(true);
            this.m_objects = new Dictionary(true);
            this.m_backgrounds = new Dictionary(true);
            this.m_imageSprite = new Sprite();
            this.m_bgHolder = new Sprite();
            this.m_senderHolder = new Sprite();
            this.m_recipientHolder = new Sprite();
            this.m_objectHolder = new Sprite();
            super();
            this.m_data = _arg1;
            if (_arg2){
                this.m_curSender = _arg2.leftPart;
                this.m_curObject = _arg2.middlePart;
                this.m_curRecipient = _arg2.rightPart;
                StatsManager.count(StatsCounterType.CARDMAKER, StatsKingdomType.VDAY_2011, StatsPhylumType.CARDVIEWER, "view");
            } else {
                this.m_curSender = Math.ceil((Math.random() * this.m_data["senders"].length()));
                this.m_curObject = Math.ceil((Math.random() * this.m_data["objects"].length()));
                this.m_curRecipient = Math.ceil((Math.random() * this.m_data["recipients"].length()));
            };
            this.init();
        }
        public function get leftID():int{
            return (this.m_curSender);
        }
        public function get centerID():int{
            return (this.m_curObject);
        }
        public function get rightID():int{
            return (this.m_curRecipient);
        }
        public function changeCard(_arg1:ValentineCard):void{
            this.m_curSender = _arg1.leftPart;
            this.m_curObject = _arg1.middlePart;
            this.m_curRecipient = _arg1.rightPart;
            if (this.m_recipientHolder.numChildren > 0){
                this.m_recipientHolder.removeChildAt(0);
            };
            if (this.m_recipients[this.m_curRecipient]){
                this.m_recipientHolder.addChild(this.m_recipients[this.m_curRecipient]);
            };
            if (this.m_senderHolder.numChildren > 0){
                this.m_senderHolder.removeChildAt(0);
            };
            if (this.m_senders[this.m_curSender]){
                this.m_senderHolder.addChild(this.m_senders[this.m_curSender]);
            };
            if (this.m_objectHolder.numChildren > 0){
                this.m_objectHolder.removeChildAt(0);
            };
            if (this.m_objects[this.m_curObject]){
                this.m_objectHolder.addChild(this.m_objects[this.m_curObject]);
            };
            dispatchEvent(new Event(MakerPanel.PREPARE, true));
        }
        public function swapRecipient(_arg1:AWEvent):void{
            this.m_curRecipient++;
            if (this.m_curRecipient > this.m_recipients["length"]){
                this.m_curRecipient = 1;
            };
            if (this.m_recipients[this.m_curRecipient]){
                this.m_recipientHolder.removeChildAt(0);
                this.m_recipientHolder.addChild(this.m_recipients[this.m_curRecipient]);
            };
            StatsManager.count(StatsCounterType.CARDMAKER, StatsKingdomType.VDAY_2011, StatsPhylumType.CARDMAKER, "iconchange", "right");
            dispatchEvent(new Event(MakerPanel.PREPARE, true));
        }
        public function swapSender(_arg1:AWEvent):void{
            this.m_curSender++;
            if (this.m_curSender > this.m_senders["length"]){
                this.m_curSender = 1;
            };
            if (this.m_senders[this.m_curSender]){
                this.m_senderHolder.removeChildAt(0);
                this.m_senderHolder.addChild(this.m_senders[this.m_curSender]);
            };
            StatsManager.count(StatsCounterType.CARDMAKER, StatsKingdomType.VDAY_2011, StatsPhylumType.CARDMAKER, "iconchange", "left");
            dispatchEvent(new Event(MakerPanel.PREPARE, true));
        }
        public function swapObject(_arg1:AWEvent):void{
            this.m_curObject++;
            if (this.m_curObject > this.m_objects["length"]){
                this.m_curObject = 1;
            };
            if (this.m_objects[this.m_curObject]){
                this.m_objectHolder.removeChildAt(0);
                this.m_objectHolder.addChild(this.m_objects[this.m_curObject]);
            };
            StatsManager.count(StatsCounterType.CARDMAKER, StatsKingdomType.VDAY_2011, StatsPhylumType.CARDMAKER, "iconchange", "center");
            dispatchEvent(new Event(MakerPanel.PREPARE, true));
        }
        public function swapBackground(_arg1:AWEvent):void{
            this.m_curBackground++;
            if (this.m_curBackground > this.m_backgrounds["length"]){
                this.m_curBackground = 1;
            };
            this.m_bgHolder.removeChildAt(0);
            this.m_bgHolder.addChild(this.m_backgrounds[this.m_curBackground]);
            dispatchEvent(new Event(MakerPanel.PREPARE, true));
        }
        protected function makeLoadingText(_arg1:String):TextField{
            var _local2:TextField = new TextField();
            _local2.text = _arg1;
            _local2.height = 0;
            _local2.selectable = false;
            _local2.embedFonts = true;
            _local2.antiAliasType = AntiAliasType.ADVANCED;
            _local2.gridFitType = GridFitType.PIXEL;
            _local2.autoSize = TextFieldAutoSize.CENTER;
            var _local3:TextFormat = new TextFormat();
            _local3.font = EmbeddedArt.DEFAULT_FONT_NAME_BOLD;
            _local3.color = EmbeddedArt.darkBlueTextColor;
            _local3.align = TextFormatAlign.CENTER;
            _local3.size = 16;
            _local2.setTextFormat(_local3);
            return (_local2);
        }
        protected function init():void{
            var sendernode:* = null;
            var repnode:* = null;
            var objnode:* = null;
            var sendurl:* = null;
            var sendid:* = 0;
            var image_senders:* = null;
            var repurl:* = null;
            var repid:* = 0;
            var image_recipients:* = null;
            var objurl:* = null;
            var objid:* = 0;
            var image_obj:* = null;
            this.addChild(this.m_imageSprite);
            this.m_imageSprite.addChild(this.m_bgHolder);
            this.m_bgHolder.addChild((new (ValentineDialog.assetDict["valentineBG"])() as DisplayObject));
            var loadingText1:* = this.makeLoadingText(ZLoc.t("Dialogs", "FrameLoading"));
            var loadingText2:* = this.makeLoadingText(ZLoc.t("Dialogs", "FrameLoading"));
            var loadingText3:* = this.makeLoadingText(ZLoc.t("Dialogs", "FrameLoading"));
            this.m_senderHolder.addChild(loadingText1);
            loadingText1.x = 20;
            loadingText1.y = 140;
            this.m_objectHolder.addChild(loadingText2);
            loadingText2.x = 40;
            loadingText2.y = 140;
            this.m_recipientHolder.addChild(loadingText3);
            loadingText3.x = 100;
            loadingText3.y = 140;
            this.m_imageSprite.addChild(this.m_senderHolder);
            this.m_senderHolder.x = 10;
            this.m_senderHolder.y = -5;
            this.m_imageSprite.addChild(this.m_recipientHolder);
            this.m_recipientHolder.x = 213;
            this.m_recipientHolder.y = -5;
            this.m_imageSprite.addChild(this.m_objectHolder);
            this.m_objectHolder.x = 131;
            this.m_senders["length"] = 0;
            this.m_recipients["length"] = 0;
            this.m_objects["length"] = 0;
            this.m_backgrounds["length"] = 0;
            var callback:* = function (_arg1:Sprite, _arg2:int, _arg3:Sprite, _arg4:Dictionary, _arg5:int, _arg6:Event):void{
                if (((_arg6.target) && (_arg6.target.content))){
                    _arg4[_arg2] = _arg6.target.content;
                    var _local7 = _arg4;
                    var _local8 = "length";
                    var _local9 = (_local7[_local8] + 1);
                    _local7[_local8] = _local9;
                    if (_arg2 == _arg5){
                        _arg1.removeChildAt(0);
                        _arg1.addChild(_arg6.target.content);
                        _arg3.dispatchEvent(new Event(MakerPanel.PREPARE, true));
                    };
                };
            };
            for each (sendernode in this.m_data["senders"]) {
                sendurl = sendernode.@url;
                sendid = int(sendernode.@id);
                image_senders = LoadingManager.load(Global.getAssetURL(sendurl), Curry.curry(callback, this.m_senderHolder, sendid, this, this.m_senders, this.m_curSender));
            };
            for each (repnode in this.m_data["recipients"]) {
                repurl = repnode.@url;
                repid = int(repnode.@id);
                image_recipients = LoadingManager.load(Global.getAssetURL(repurl), Curry.curry(callback, this.m_recipientHolder, repid, this, this.m_recipients, this.m_curRecipient));
            };
            for each (objnode in this.m_data["objects"]) {
                objurl = objnode.@url;
                objid = int(objnode.@id);
                image_obj = LoadingManager.load(Global.getAssetURL(objurl), Curry.curry(callback, this.m_objectHolder, objid, this, this.m_objects, this.m_curObject));
            };
        }

    }
}//package Display.ValentineUI 
